﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.wlkc2011.Module.Default.model;
using Jxym.DBUtility;
using System.Data.SqlClient;

namespace Jxym.wlkc2011.Module.Default.SERVER.User
{
    public partial class DepmetAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string returnJsonStr = "";

                MsSqlDal<Depmet> iD = new MsSqlDal<Depmet>();

                string text = ""; if (Request.Params["text"] != null) { text = Request.Params["text"]; }
                int parentNodeId = 0; if (Request.Params["parentnode"] != null) { parentNodeId = Convert.ToInt32(Request.Params["parentnode"]); }
                int nodeId = 0; if (Request.Params["nodeId"] != null) { nodeId = Convert.ToInt32(Request.Params["nodeId"]); }

                if (text != "")
                {
                    if (nodeId != 0)
                    {
                        SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", nodeId), new SqlParameter("@Name", text) };
                        iD.Updata(parameters);
                        returnJsonStr = "{'success':true,'msg':'编辑完成'}";
                    }
                    else
                    {
                        SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Name", text), new SqlParameter("@ParentID", parentNodeId) };
                        iD.Add(parameters);
                        returnJsonStr = "{'success':true,'msg':'添加完成'}";
                    }
                }
                else
                {
                    returnJsonStr = "{'success':false,'msg':'添加失败'}";
                }
                Response.Write(returnJsonStr);
            }
        }
    }
}